/*
 * @Author: mikey.zhaopeng 
 * @Date: 2018-12-30 11:20:05 
 * @Last Modified by: mikey.zhaopeng
 * @Last Modified time: 2019-01-09 20:28:30
 */
import 'package:flutter/material.dart';

//导入五个导航页
import './circle.dart' show CirclePage;
import './mine.dart' show MinePage;
import './rank.dart' show RankPage;
import './game.dart' show GamePage;
import './home/home.dart' show HomePage;
//导入工具类
import '../utils/utils.dart' show Utils;

class TabPage extends StatefulWidget {
  @override
  _TabPageState createState() => _TabPageState();
}

class _TabPageState extends State<TabPage> with SingleTickerProviderStateMixin {
  int _tabIndex = 0; //默认显示的tab
  PageController pageController;
  List<Widget> _bodys;

  @override
  void initState() {
    super.initState();
    //初始化页面数组
    _bodys = [HomePage(), GamePage(), CirclePage(), RankPage(), MinePage()];
    pageController = new PageController(initialPage: _tabIndex);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: PageView.builder(
        itemBuilder: (BuildContext context, int index) {
          return _bodys[_tabIndex];
        },
        controller: pageController,
        itemCount: _bodys.length,
        physics: NeverScrollableScrollPhysics(),
        onPageChanged: (int index) {
          print(index);
        },
      ),
      bottomNavigationBar: BottomNavigationBar(
        // fixedColor:Colors.red,
        type: BottomNavigationBarType.fixed,
        onTap: (int index) {
          setState(() {
            _tabIndex = index;
          });
        },
        currentIndex: _tabIndex,
        items: <BottomNavigationBarItem>[
          BottomNavigationBarItem(
              title: Text('首页'),
              icon: Utils.getTabIcon('assets/images/dd.png'),
              activeIcon: Utils.getTabIcon('assets/images/d.png')),
          BottomNavigationBarItem(
              title: Text('游戏'),
              icon: Utils.getTabIcon('assets/images/ee.png'),
              activeIcon: Utils.getTabIcon('assets/images/e.png')),
          BottomNavigationBarItem(
              title: Text('圈子'),
              icon: Utils.getTabIcon('assets/images/ff.png'),
              activeIcon: Utils.getTabIcon('assets/images/f.png')),
          BottomNavigationBarItem(
              title: Text('排行'),
              icon: Utils.getTabIcon('assets/images/gg.png'),
              activeIcon: Utils.getTabIcon('assets/images/g.png')),
          BottomNavigationBarItem(
              title: Text('我的'),
              icon: Utils.getTabIcon('assets/images/hh.png'),
              activeIcon: Utils.getTabIcon('assets/images/h.png')),
        ],
      ),
    );
  }
}
